//
//  CatTypeDetail.m
//  AutoHome
//
//  Created by wqh on 15-5-13.
//  Copyright (c) 2015年 Wqh. All rights reserved.
//

#import "CarTypeDetail.h"
#import "TopTabControl.h"
#import "BaseViewController.h"
@interface CarTypeDetail ()<TopTabControlDataSource>
{
    NSMutableArray *_viewControllersArr;
}
@property (nonatomic) TopTabControl *tabControl;
@property (nonatomic) NSMutableArray *carTypeInfo;

@end

@implementation CarTypeDetail

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationController.navigationBar.hidden = YES;
    self.navigationController.navigationBar.translucent = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.tabBarController.tabBar.translucent = YES;
    
    
    

    
    [self initData];
    [self createTabControl];
    [self addButton];
    
}

- (void)createTabControl {
    self.tabControl = [[TopTabControl alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height)];
    self.tabControl.datasource = self;
    [self.tabControl reloadData];
    self.tabControl.showIndicatorView = YES;
    [self.view addSubview:self.tabControl];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
}

- (void)initData {
    _viewControllersArr = [NSMutableArray arrayWithArray:@[@"CarTypePrice",@"CarTypePictures",@"CarTypePublicPraise",@"CarTypeReducePrice"]];
    self.carTypeInfo = [NSMutableArray arrayWithArray:@[@"报价",@"图片",@"口碑",@"降价"]];
}
/**
 *  添加两个按钮，返回按钮，和底部按钮
 */
- (void)addButton {
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeSystem ];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"bar_btn_icon_returntext"] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(10, 27, 50, 30);
    [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
//    UIButton *bottomBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//    [bottomBtn setTitle:@"地图显示" forState:UIControlStateNormal];
//    bottomBtn.frame = CGRectMake(0, kScreenHeight-49, kScreenWidth, 49);
//    [self.view addSubview:bottomBtn];
    
}

- (void)backBtnClick:(UIButton *)button {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"displayButton" object:@(1)];
    [self.navigationController popViewControllerAnimated:YES];
}

//设置菜单的个数
- (NSInteger)TopTabMenuCount:(TopTabControl *)tabCtrl
{
    return self.carTypeInfo.count;
}

- (CGFloat)TopTabX:(TopTabControl *)tabCtrl {
    return 70;
}

- (CGFloat)TopTabHeight:(TopTabControl *)tabCtrl {
    return 44;
}

- (CGFloat)TopTabWidth:(TopTabControl *)tabCtrl {
    return 240;
}

- (TopTabMenuItem *)TopTabControl:(TopTabControl *)tabCtrl itemAtIndex:(NSUInteger)index {
    TopTabMenuItem *item = [[TopTabMenuItem alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:self.carTypeInfo[index] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor customBlueColor] forState:UIControlStateSelected];
    button.frame = item.bounds;
    button.userInteractionEnabled = NO;
    
    [item addSubview:button];
    
    return item;
}

- (TopTabPage *)TopTabControl:(TopTabControl *)tabCtrl pageAtIndex:(NSUInteger)index {
    
    TopTabPage *page = [[TopTabPage alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-49-64)];
    page.backgroundColor = [UIColor greenColor];
    
    Class className = NSClassFromString(_viewControllersArr[index]);
    BaseViewController *vc = [[className alloc] init];
    
    vc.systemId = self.systemId;
    vc.typeId = self.typeId;
    vc.titleName = self.titleName;
    
    vc.view.frame = page.bounds;
    
    vc.myPageJumpBlcok = ^ (UIViewController *vc) {
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    //page.vc = vc;
    [page addSubview:vc.view];
    
    [self addChildViewController:vc];
    
   // [self transitionFromViewController:(UIViewController *) toViewController:<#(UIViewController *)#> duration:<#(NSTimeInterval)#> options:<#(UIViewAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];
    
    return page;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
